<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>延缓执行若干秒和纳秒</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.time-nanosleep" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">time_nanosleep</h1>
  <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">time_nanosleep</span> &mdash; <span class="dc-title">延缓执行若干秒和纳秒</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.time-nanosleep-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>time_nanosleep</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$seconds</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$nanoseconds</code></span>
   ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   程序延缓执行指定数量的 <code class="parameter">seconds</code> 和 <code class="parameter">nanoseconds</code>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.time-nanosleep-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">seconds</code></dt>

     <dd>

      <p class="para">
       必须是一个非负整数。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">nanoseconds</code></dt>

     <dd>

      <p class="para">
       必须是一个小于1亿的非负整数。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.time-nanosleep-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
  <p class="para">
   如果延迟被中断，一个关联数组会返回，内容为：
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      <em>seconds</em> - 延迟剩余未执行的秒数
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      <em>nanoseconds</em> - 延迟剩余未执行的纳秒数
     </span>
    </li>
   </ul>
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.time-nanosleep-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.3.0</td>
       <td>
        至此之后该函数在Windows平台下可用。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.time-nanosleep-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4550">
    <p><strong>Example #1 <span class="function"><strong>time_nanosleep()</strong></span> 的例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Careful!&nbsp;This&nbsp;won't&nbsp;work&nbsp;as&nbsp;expected&nbsp;if&nbsp;an&nbsp;array&nbsp;is&nbsp;returned<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">time_nanosleep</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">500000000</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Slept&nbsp;for&nbsp;half&nbsp;a&nbsp;second.\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;better:<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">time_nanosleep</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">500000000</span><span style="color: #007700">)&nbsp;===&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Slept&nbsp;for&nbsp;half&nbsp;a&nbsp;second.\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;And&nbsp;this&nbsp;is&nbsp;the&nbsp;best:<br /></span><span style="color: #0000BB">$nano&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">time_nanosleep</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">100000</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$nano&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Slept&nbsp;for&nbsp;2&nbsp;seconds,&nbsp;100&nbsp;microseconds.\n"</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;(</span><span style="color: #0000BB">$nano&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Sleeping&nbsp;failed.\n"</span><span style="color: #007700">;<br />}&nbsp;elseif&nbsp;(</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$nano</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$seconds&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$nano</span><span style="color: #007700">[</span><span style="color: #DD0000">'seconds'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$nanoseconds&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$nano</span><span style="color: #007700">[</span><span style="color: #DD0000">'nanoseconds'</span><span style="color: #007700">];<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Interrupted&nbsp;by&nbsp;a&nbsp;signal.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Time&nbsp;remaining:&nbsp;</span><span style="color: #0000BB">$seconds</span><span style="color: #DD0000">&nbsp;seconds,&nbsp;</span><span style="color: #0000BB">$nanoseconds</span><span style="color: #DD0000">&nbsp;nanoseconds."</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.time-nanosleep-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="sleep.html" class="function" rel="rdfs-seeAlso">sleep()</a> - 延缓执行</span></li>
    <li class="member"><span class="function"><a href="usleep.html" class="function" rel="rdfs-seeAlso">usleep()</a> - 以指定的微秒数延迟执行</span></li>
    <li class="member"><span class="function"><a href="time_sleep_until.html" class="function" rel="rdfs-seeAlso">time_sleep_until()</a> - 使脚本睡眠到指定的时间为止。</span></li>
    <li class="member"><span class="function"><a href="set_time_limit.html" class="function" rel="rdfs-seeAlso">set_time_limit()</a> - 设置脚本最大执行时间</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>